﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gedea.Model.Entities;
using Gedea.Service;

namespace Gedea.WinForm.UserControls
{
    public partial class SettingsControl : UserControl
    {
        private Delegate btnCancelDeleg, btnOkDeleg;
        private bool isEditable;

        public SettingsControl(Delegate btnCancel, Delegate btnOk, bool isEditableForm)
        {
            InitializeComponent();

            btnCancelDeleg = btnCancel;
            btnOkDeleg = btnOk;
            isEditable = isEditableForm;
        }

        private void SettingsControl_Load(object sender, EventArgs e)
        {
            LoadUser();

            ToolTip label8Info = new ToolTip();

            toolTip1.AutoPopDelay = 5000;
            toolTip1.InitialDelay = 1000;
            toolTip1.ReshowDelay = 500;

            toolTip1.ShowAlways = true;

            label8Info.SetToolTip(this.label8, "Defina el largo que desea utilizar para la Referencia Unívoca del Débito");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            btnCancelDeleg.DynamicInvoke();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            btnOkDeleg.DynamicInvoke(GenerateViewUser());
        }

        private User GenerateViewUser()
        {
            User user = Credentials.currentUser;

            //user. = comboBox1.SelectedValue;
            user.LargoReferenciaUnivDelDev = Convert.ToInt32(numericUpDown1.Value);
            user.RecordsDuration = Convert.ToInt32(numericUpDown2.Value);

            return user;
        }

        private void LoadUser()
        {
            if (isEditable)
            {
                //comboBox1.SelectedValue = Credentials.currentUser...;
                numericUpDown1.Value = Credentials.currentUser.LargoReferenciaUnivDelDev;
                numericUpDown2.Value = Credentials.currentUser.RecordsDuration;

                button1.Text = "Editar";

            }
        }
    }
}
